package com.fyzk.activity.user;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.fyzk.activity.user.accountdetail.AccountDetailListAdapter;
import com.fyzk.bean.AccountDetailsBean;
import com.fyzk.data.preference.MySharedPreferences;
import com.fyzk.interfaces.MoreInterface;
import com.fyzk.interfaces.ReTryInterface;
import com.fyzk.interfaces.UpdateInterface;
import com.tyjc.lottery.R;
import com.fyzk.utils.L;
import com.fyzk.view.MsgListView;

import java.util.ArrayList;
import java.util.List;


/**
 * 账户明细记录View
 * 
 * @author fxs
 * 
 */
public class ZhangHuMXRecordView extends FrameLayout {

	private String TAG = this.getClass().getSimpleName();

	NetProgressView netProgressView;
	MsgListView listViewExt;
	TextView balance;
	AccountDetailListAdapter listAdapter;
	public List<AccountDetailsBean> infos;
	private Context context;

	public ZhangHuMXRecordView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.context = context;
		init();
	}

	public ZhangHuMXRecordView(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public ZhangHuMXRecordView(Context context) {
		this(context, null);
	}

	public void setMoreInterface(MoreInterface moreInterface) {
		listViewExt.setMoreInterface(moreInterface);
	}

	public void setUpdateInterface(UpdateInterface updateInterface) {
		listViewExt.setUpdateInterface(updateInterface);
	}

	private void init() {
		View.inflate(context, R.layout.layout_recordlist_zhmx, this);
		netProgressView = (NetProgressView) findViewById(R.id.recordProgressView);
		listViewExt = (MsgListView) findViewById(R.id.recordlist);
		balance = (TextView) findViewById(R.id.recharge_balance);
		balance.setText("账户彩金:¥"+ MySharedPreferences.getInstance().getBalance());
		listViewExt.setItemsCanFocus(false);
		listViewExt.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
		infos = new ArrayList<>();
		listAdapter = new AccountDetailListAdapter(context, infos);
		listViewExt.setAdapter(listAdapter);
	}



	public void updateFinish() {
		listViewExt.onRefreshComplete();
	}

	/**
	 * 刷新列表
	 * 
	 * @param infos
	 */
	public void refrashInfos(ArrayList<AccountDetailsBean> infos) {
		netProgressView.setVisibility(View.GONE);
		this.infos.clear();
		if (null != infos) {
			this.infos.addAll(infos);
		}
		listAdapter.notifyDataSetChanged();
	}

	public void showData() {
		netProgressView.setVisibility(View.VISIBLE);
		netProgressView.dismiss();

	}

	public void showLoading() {
		netProgressView.setVisibility(View.VISIBLE);
		netProgressView.waiting();
	}

	public void showNoneRecord(String msg) {
		netProgressView.setVisibility(View.VISIBLE);
		netProgressView.noneRecord(msg);
	}

	public void showFail(String msg) {
		infos.clear();
		listAdapter.notifyDataSetChanged();
		netProgressView.setVisibility(View.VISIBLE);
		netProgressView.fail(msg);
	}

	public void setRetryInterface(ReTryInterface reTry) {
		netProgressView.setRetryInterface(reTry);
	}

	public void initRecordList(List<AccountDetailsBean> infos) {
		if (infos.size() > 0) {
			L.v(TAG, "initRecordList>>>>>>");
			netProgressView.setVisibility(View.GONE);
			if (null != infos) {
				this.infos.clear();
				this.infos.addAll(infos);
			}

			if (infos.size() < 20) {
				listViewExt.listMore.setClickable(false);
				listViewExt.listMore.setTextStr("无更多数据");
			}else{
				listViewExt.listMore.setTextStr("获取更多");
				listViewExt.listMore.endNet();
			}
			listAdapter.notifyDataSetChanged();
		}
	}

	public void addRecordInfos(List<AccountDetailsBean> infos) {
		netProgressView.setVisibility(View.GONE);
		if (null != infos) {
			this.infos.addAll(infos);
		}
		if (infos.size() < 20) {
			listViewExt.listMore.setClickable(false);
			listViewExt.listMore.setTextStr("无更多数据");
		}else{
			listViewExt.listMore.setTextStr("获取更多");
			listViewExt.listMore.endNet();
		}
		listAdapter.notifyDataSetChanged();
	}
}
